package com.dc.bobaoge.project.base.core.injector.impl;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.methods.Insert;
import com.baomidou.mybatisplus.core.injector.methods.Update;
import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.dc.bobaoge.project.base.core.injector.method.CustomInsert;
import com.dc.bobaoge.project.base.core.injector.method.CustomUpdate;
import com.dc.bobaoge.project.base.core.injector.method.CustomUpdateById;
import com.own.component.mybatis.hook.CustomMybatisHook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * DefaultCustomMybatisHookImpl
 *
 * @author chenxueli
 * @date 2024-01-12 11:52:00
 */
@Slf4j
@Component
public class SyncCustomMybatisHookImpl implements CustomMybatisHook {

    private static final Set<String> INCLUDE_TABLE_NAME_LIST = new HashSet<>();

    static {
        INCLUDE_TABLE_NAME_LIST.add("t_v3_advertisement");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_title");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_local_feature");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_recruit");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_apprentice");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_find_job");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_comment");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_comment_complaint");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_complaint");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_collection_user_history");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_message_praise_user_history");
        INCLUDE_TABLE_NAME_LIST.add("own_system_account");
        INCLUDE_TABLE_NAME_LIST.add("own_system_user");
        INCLUDE_TABLE_NAME_LIST.add("own_system_user_info");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_system_user_extra_info");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_authentication_info_history");
        INCLUDE_TABLE_NAME_LIST.add("t_v3_authentication_info_update");
        INCLUDE_TABLE_NAME_LIST.add("own_bill_history");
//        INCLUDE_TABLE_NAME_LIST.add("t_v3_contact_user");

        INCLUDE_TABLE_NAME_LIST.add("bc_msg_type");
        INCLUDE_TABLE_NAME_LIST.add("bc_message");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_comment");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_browser");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_browsers");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_laud");
        INCLUDE_TABLE_NAME_LIST.add("bc_collect_msg");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_report");
        INCLUDE_TABLE_NAME_LIST.add("bc_msg_comreport");
        INCLUDE_TABLE_NAME_LIST.add("bc_adv_msg");
        INCLUDE_TABLE_NAME_LIST.add("bc_adv_browser_count");
        INCLUDE_TABLE_NAME_LIST.add("bc_trade_records");
//        INCLUDE_TABLE_NAME_LIST.add("bc_cer_person");
//        INCLUDE_TABLE_NAME_LIST.add("bc_cer_company");
        INCLUDE_TABLE_NAME_LIST.add("bc_cer_msg");
        INCLUDE_TABLE_NAME_LIST.add("bc_user");
//        INCLUDE_TABLE_NAME_LIST.add("bc_cer_levelsub");
    }

    /**
     * 执行方法
     *
     * @param methodList  方法列表
     * @param mapperClass mapper类
     * @param tableInfo   表信息
     */
    @Override
    public void run(List<AbstractMethod> methodList, Class<?> mapperClass, TableInfo tableInfo) {
        if (INCLUDE_TABLE_NAME_LIST.contains(tableInfo.getTableName())) {
            if (methodList.removeIf(method -> method instanceof Insert)) {
                methodList.add(new CustomInsert());
            }
            if (methodList.removeIf(method -> method instanceof Update)) {
                methodList.add(new CustomUpdate());
            }
            if (methodList.removeIf(method -> method instanceof UpdateById)) {
                methodList.add(new CustomUpdateById());
            }
        }
    }

}
